package com.liziba.demo.slice;

import com.liziba.demo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice implements Component.LongClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        // 1、通过id查询到组件
        Text text = (Text) this.findComponentById(ResourceTable.Id_text_helloworld);

        // 2、给组件设置长按事件
        text.setLongClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /**
     * 长按事件触发回调的方法，此方法来自于实现Component.LongClickedListener重写的方法
     *
     * @param component
     */
    @Override
    public void onLongClicked(Component component) {
        Text text = (Text) component;
        text.setText("你好，李子捌！");
    }
}
